package opengles;

import android.content.Context;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;

/**
 * Created by freehyan on 9/8/2016.
 */
public abstract class GLESPass {
    protected GLESProgram mPassProgram;
    protected FloatBuffer vertexBuffer, textureVerticesBuffer;
    protected ShortBuffer drawListBuffer;
    protected int mPositionHandle;
    protected int mTextureCoordHandle;
    protected int mTexSamplerHandle;

    protected short drawOrder[] = {0, 1, 2, 0, 2, 3}; // order to draw vertices
    protected static final int COORDS_PER_VERTEX = 2;
    protected final int vertexStride = COORDS_PER_VERTEX * 4; // 4 bytes per vertex

    public GLESPass(Context activityContext, float[] textureCoord) {

        ByteBuffer bb = ByteBuffer.allocateDirect(Coordinates.SquareCoords.length * 4);
        bb.order(ByteOrder.nativeOrder());
        vertexBuffer = bb.asFloatBuffer();
        vertexBuffer.put(Coordinates.SquareCoords);
        vertexBuffer.position(0);

        ByteBuffer dlb = ByteBuffer.allocateDirect(drawOrder.length * 2);
        dlb.order(ByteOrder.nativeOrder());
        drawListBuffer = dlb.asShortBuffer();
        drawListBuffer.put(drawOrder);
        drawListBuffer.position(0);

        ByteBuffer bb2 = ByteBuffer.allocateDirect(textureCoord.length * 4);
        bb2.order(ByteOrder.nativeOrder());
        textureVerticesBuffer = bb2.asFloatBuffer();
        textureVerticesBuffer.put(textureCoord);
        textureVerticesBuffer.position(0);

        mPassProgram = new GLESProgram();
    }

    public abstract void render();
}
